package com.kedacom.ctsp.authz.oauth2.core.vo;

import com.google.common.collect.Maps;
import com.kedacom.ctsp.authz.entity.AuthPerson;
import com.kedacom.ctsp.authz.entity.AuthRole;
import com.kedacom.ctsp.authz.entity.AuthUser;
import com.kedacom.ctsp.authz.entity.Authentication;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

@Data
public class PlainAuthentication implements Authentication {

    protected AuthUser user;

    protected String password;
    protected Set<AuthRole> roles;
    protected transient Set<String> roleSigns;
    protected AuthPerson person;

    protected Map<String, Serializable> attributes = Maps.newHashMap();


    public PlainAuthentication() {

    }

    public PlainAuthentication(Authentication authentication) {
        this.user = authentication.getUser();
        this.password = authentication.getPassword();
        this.roles = authentication.getRoles();
        this.roleSigns = authentication.getRoleSigns();
        this.person = authentication.getPerson();
        this.attributes = authentication.getAttributes();
    }


    @Override
    public <T extends Serializable> Optional<T> getAttribute(String name) {
        return Optional.ofNullable((T) attributes.get(name));
    }

    @Override
    public void setAttribute(String s, Serializable serializable) {

    }

    @Override
    public <T extends Serializable> T removeAttributes(String s) {
        return null;
    }
}
